package org.mzy.basic.controller;

import org.mzy.basic.dto.EmailCodeDto;
import org.mzy.basic.dto.PhoneSmsCodeDto;
import org.mzy.basic.service.IVerifyCodeService;
import org.mzy.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Package: org.mzy.basic.controller
 * @ClassName: verifyCodeController
 * @Date:2022/10/18 15:12
 * @Description:
 */
@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;


    /**
     * 获取图形验证码
     */
    @GetMapping("/image/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String uuidKey) {
        String base64Code = verifyCodeService.getImageCode(uuidKey);
        return AjaxResult.me().success(base64Code);
    }

    /**
     * 获取短信验证码
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid PhoneSmsCodeDto dto) {
        verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }

    /**
     * 获取短信验证码
     */
    @PostMapping("/smsCode2")
    public AjaxResult smsCode2(@RequestBody @Valid PhoneSmsCodeDto dto) {
        verifyCodeService.smsCode2(dto);
        return AjaxResult.me().success();
    }

    /**
     * 获取邮箱验证码
     */
    @PostMapping("/emailCode")
    public AjaxResult emailCode(@RequestBody @Valid EmailCodeDto dto) {
        verifyCodeService.emailCode(dto);
        return AjaxResult.me().success();
    }
}
